package com.zyd.shiro.controller.admin;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import com.zyd.shiro.business.entity.Resources;
import com.zyd.shiro.business.vo.ResourceConditionVO;
import com.zyd.shiro.business.vo.TalentShareVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import com.zyd.shiro.persistence.beans.Talentshare;
import com.zyd.shiro.business.service.MallTalentshareService;

import com.zyd.shiro.framework.object.PageResult;
import com.zyd.shiro.framework.object.ResponseVO;
import com.zyd.shiro.util.ResultUtil;
/**
 * 控制器层
 * @author RookieWZW
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/talentshare")
public class TalentshareController {

	@Autowired
	private MallTalentshareService talentshareService;
	
	/**
	 * 查询全部数据
	 * @return
	 */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public ResponseVO findAll(){
		 return ResultUtil.success("查询成功",talentshareService.findAll());
		
	}
	@RequiresPermissions("talentshare")
	@PostMapping("/list")
	public PageResult getAll(TalentShareVO data) {
        Page<Talentshare>page =	 talentshareService.findPageByVO(data);
        return ResultUtil.tablePage((long) page.getTotalElements(),page.getContent());
	}

	/**
	 * 根据条件查询 状态   简历/求职
	 * @param state
	 * @param mold
	 * @return
	 */
	@RequestMapping(value = "/{state}/{mold}",method=RequestMethod.GET)
	public ResponseVO findAllByStateAndMold(@PathVariable Integer state,@PathVariable Integer mold){
		return ResultUtil.success("查询成功",talentshareService.findALLByStateAndMold(state, mold));
	}

	/**
	 * 根据条件查询  全职/兼职  简历/求职  状态
	 * @param type
	 * @param mold
	 * @param state
	 * @return
	 */
	@RequestMapping(value = "/{type}/{mold}/{state}",method=RequestMethod.GET)
	public ResponseVO findAllByTypeAndAndMoldAAndState(@PathVariable Integer type,@PathVariable Integer mold,@PathVariable Integer state){
		return ResultUtil.success("查询成功",talentshareService.findAllByTypeAndAndMoldAAndState(type, mold, state));
	}

	/**
	 * 获得未审核列表
	 * @return
	 */
	@PostMapping(value="/nolist")
	public ResponseVO getList( ){
		return ResultUtil.success("查询成功",talentshareService.findAllByState(0));
	}

	/**
	 * 认证审核成功
	 * @param id
	 * @return
	 */
	@PutMapping(value="/success/{id}")
	public ResponseVO examSuccess(@PathVariable Integer id ){
		talentshareService.updateState(1,id);
		return ResultUtil.success("修改成功");
	}

	@PostMapping(value = "/remove")
	public ResponseVO remove(Long[] ids) {
		if (null == ids) {
			return ResultUtil.error(500, "请至少选择一条记录");
		}
		for (Long id : ids) {
			talentshareService.delete(Math.toIntExact(id));
		}

		return ResultUtil.success("成功删除 [" + ids.length + "] 个资源");
	}

	/**
	 * 认证审核失败
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/fault/{id}",method=RequestMethod.PUT)
	public ResponseVO examFault(@PathVariable Integer id ){
		talentshareService.updateState(2,id);
		return ResultUtil.success("修改成功");
	}

	/**
	 * 根据用户id查找
	 * @param user_id
	 * @return
	 */
	@RequestMapping(value="/u/{user_id}",method=RequestMethod.GET)
	public ResponseVO findALLByUserID(@PathVariable Integer user_id){
		return ResultUtil.success("查询成功", talentshareService.findALLByUserID(user_id));
	}

	/**
	 * 根据ID查询
	 * @param id ID
	 * @return
	 */
	@RequestMapping(value="/i/{id}",method=RequestMethod.GET)
	public ResponseVO findOne(@PathVariable Integer id){
		return ResultUtil.success("查询成功", talentshareService.findOne(id));	
		
	}
	
	/**
	 * 分页查询全部数据
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/{page}/{size}",method=RequestMethod.GET)
	public ResponseVO findPage(@PathVariable int page,@PathVariable int size){		
		Page<Talentshare> pageList = talentshareService.findPage(page, size);
		return ResultUtil.success("查询成功",new PageResult(pageList.getTotalElements(), pageList.getContent() ) );	
	}
	
	/**
	 * 分页+多条件查询 
	 * @param searchMap 查询条件封装
	 * @param page 页码
	 * @param size 页大小
	 * @return 分页结果
	 */
	@RequestMapping(value="/{page}/{size}",method=RequestMethod.POST)
	public ResponseVO findSearch(@RequestBody Map searchMap ,@PathVariable int page,@PathVariable int size){		
		Page<Talentshare> pageList = talentshareService.findSearch(searchMap, page, size);
		return ResultUtil.success("查询成功",  new PageResult(pageList.getTotalElements(), pageList.getContent()) );		
	}
	
	/**
	 * 增加
	 * @param talentshare
	 */
	@RequestMapping(value="/",method=RequestMethod.POST)
	public ResponseVO add(@RequestBody Talentshare talentshare  ){
		talentshareService.add(talentshare);			
		return ResultUtil.success("增加成功");
	}
	
	/**
	 * 修改
	 * @param talentshare
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResponseVO update(@RequestBody Talentshare talentshare,@PathVariable Integer id ){
		talentshare.setId(id);
		talentshareService.update(talentshare);		
		return ResultUtil.success("修改成功");
	}
	
	/**
	 * 删除
	 * @param id
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public ResponseVO delete(@PathVariable Integer id ){
		talentshareService.delete(id);
		return ResultUtil.success("删除成功");
	}
	
}
